/*
 *     Prionace - A file navigator to manage your files
 *
 *     Copyright (C) 2012 Francivan Bezerra
 *
 *     This file is part of Prionace.
 *
 *     Prionace is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     Prionace is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 *
 *     You should have received a copy of the GNU General Public License
 *     along with Prionace.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.fba.prionace.ui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.io.FileNotFoundException;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JSplitPane;
import javax.swing.WindowConstants;

import org.fba.prionace.ui.viewer.IconsViewer;

public class PrionaceWindow extends JFrame {

	private JSplitPane split;

	private ShortcutsPane shortcutsPane;

	private FilesPane filesPane;

	public PrionaceWindow() {
		super();
		init();
		addViewer(System.getProperty("user.home"));
	}

	public PrionaceWindow(String path) {
		super();
		init();
		addViewer(path);
	}

	private void init() {
		split = new JSplitPane();
		shortcutsPane = new ShortcutsPane();
		filesPane = new FilesPane();

		new PanesManager(shortcutsPane, filesPane);

		filesPane.setPreferredSize(new Dimension(1, 1));

		split.setOneTouchExpandable(true);
		split.setLeftComponent(shortcutsPane);
		split.setRightComponent(filesPane);

		ImageIcon icon = new ImageIcon(getClass().getResource(
				"/icons/prionace_logo_48x48.png"));
		setIconImage(icon.getImage());

		setLayout(new BorderLayout());
		add(split, BorderLayout.CENTER);

		setTitle("Prionace");
		setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
	}

	private void addViewer(String path) {
		// TODO pegar o viewer de um viewer factory
		try {
			filesPane.addViewer(new IconsViewer(path));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}
}
